package cn.tedu.fy.pethome.controller;

import cn.tedu.fy.pethome.pojo.vo.CategoryListItemsVO;
import cn.tedu.fy.pethome.pojo.vo.GoodsListItemsVO;
import cn.tedu.fy.pethome.service.ICategoryService;
import cn.tedu.fy.pethome.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类别的controller
 *
 * @author cl
 * @date 2022/7/29
 */
@Slf4j
@RestController
@RequestMapping("/category")
@Api(tags = "类别")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;

    @ApiOperation("查询l类别列表")
    @ApiOperationSupport(order = 401)
    @GetMapping("/list")
    public JsonResult list(){
        log.debug("处理查询类别列表");
        List<CategoryListItemsVO> categories = categoryService.list();
        return JsonResult.ok(categories);
    }


    @ApiOperation("查询子级类别列表")
    @ApiOperationSupport(order = 401)
    @GetMapping("/childrenList")
    public JsonResult getListByParentId(Long id){
        log.debug("处理查询子级类别列表");
        List<CategoryListItemsVO> categories = categoryService.getListByParentId(id);
        return JsonResult.ok(categories);
    }
}
